// packageA/components/service-order-list/index.js
const baseUrl = require('../../../api/config').dev //这里用的是ES6的写法
const WXAPI = require('../../../api/api')
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: []
    },
    isLoading:{
      type:Boolean,
      value:false
    }
  },
  // 监听传入的变量,当传入的值发生变化时,触发方法
  observers: {
    'list': function (val) {
      // val=》就是父组件传入组件中的tabsList数据
      let obj = {
        1: 3,
        2: 3,
        3: 3,
        4: 2,
        9: 1,
      };
      if (val && val.length > 0) {
        for (let i = 0; i < val.length; i++) {
          val[i].iStatus2 = obj[val[i].iStatus];
        }
      }
      this.setData({
        listData: val
      })
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    listData: [],
    imgBaseUrl: `${baseUrl['imgBaseUrl']}`
  },

  /**
   * 组件的方法列表
   */
  methods: {
    toEvaluate(e){
     const { item } = e.currentTarget.dataset
     let objStr = JSON.stringify({
       id: item.sId,
       sOrgId: item.sOrgId,
       imgUrl: item.Projects[0].sProjectImgUrl,
       name: item.Projects[0].sProjectName,
       content: item.Projects[0].sContent,
       project: item.Projects[0]
     })
      wx.navigateTo({
        url: `/packageA/pages/evaluate-service/index?type=2&objStr=${objStr}`,
      })
    },
    viewOrder(event){
      wx.navigateTo({
        url: `/packageA/pages/service-order-detail/index?id=${event.currentTarget.dataset.id}`,
      })
    },
    cancelOrder(event) {
      wx.navigateTo({
        url: `/packageA/pages/cancel-order/index?id=${event.currentTarget.dataset.id}`,
      })
    }
  }
})